package com.dsg.kf.common.util;

import java.util.List;

import org.springframework.validation.BindingResult;
import org.springframework.validation.FieldError;

/**
 * 解析出BindingResult的错误信息和字段，只返回第一个错误
 * @author Pacy.pan
 *
 */
public class ValidaterUtils {

	public static String[] getValiError(BindingResult result) {
		if (result.hasErrors()) {
			 return getErrors(result);
		}
		return null;
	}

	private static String[] getErrors(BindingResult result) {
		List<FieldError> list = result.getFieldErrors();
		FieldError error=list.get(0);
		String[] msg=new String[2];
		msg[0]=error.getField();
		msg[1]=error.getDefaultMessage();
		return msg;
	}
}
